
//调用
$(function () {
    //头部移入
    getTop();
    // 头部输入框
    getText();
    // 导航栏
    getNav();
    //轮播图
    getSwiper();
    //轮播JQ
    getSwiperS();
    //热门商品
    getHotProduct();
    //配件
    getParts();
    //TNT
    getTnt();
    //精选
    getChoiceness();
    //足迹
    getFootprint();
    //论坛精选
    getForum();
})


//头部移入
function getTop() {
    $(".header>.top_right>.shop").mouseenter(function () {
        $(".top_right .cart").show();
    });
    $(".header>.top_right>.shop").mouseleave(function () {
        $(".top_right .cart").hide();
    });
}




// 头部输入框
function getText() {
    $(".main .m_right input").on("focus", function () {
        $(".recommends>a").hide();
    })
    $(".main .m_right input").on("blur", function () {
        $(".recommends>a").show();
    })
}

// 导航栏
function getNav() {
    $(".main #m_bigbox>li").on("click", function () {
        $(this).find(".m_hide").stop().slideToggle().parent().siblings("li").find(".m_hide").stop().slideUp(1)
    });
}
//-------------------轮播图数据-----------------------
function getSwiperS() {
    $.get("../goodsAndShoppingCart/bannerGet.php", function (data) {
        // console.log(data);
        let oDiv = '';
        let newarr = [];
        data.forEach(item => {
            item = item["img"];
            newarr.push(item);
        });
        for (let k in newarr) {
            oDiv += `
        <div class="swiper-slide"><img src="${newarr[k]}" alt="" width="100%" height="100%"></div>
        `
        }
        // console.log(newarr);
        $(".swiper-wrapper").html(oDiv);
        setTimeout(function () {
            getSwiper();
        }, 50)

    }, "json")
}


//轮播区域
function getSwiper() {
    var mySwiper = new Swiper('.swiper-container', {
        direction: 'horizontal', // 垂直切换选项
        loop: true, // 循环模式选项
        loopPreventsSlide: true,//默认true，阻止
        autoplay: true,
        observer: true, //修改swiper自己或子元素时，自动初始化swiper
        observeParents: true,
        autoplay: {
            delay: 1000,
            disableOnInteraction: false,
            pauseOnMouseEnter: true,
        },

        // 如果需要分页器
        pagination: {
            el: '.swiper-pagination',
            clickable: true,
        },


        // 如果需要前进后退按钮
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },
        // 如果需要滚动条
        // scrollbar: {
        //     el: '.swiper-scrollbar',
        // },
    })
    //移出继续
    mySwiper.el.onmouseout = function () {
        mySwiper.autoplay.start();
        mySwiper.navigation.$nextEl.css("display", "none");
        mySwiper.navigation.$prevEl.css("display", "none");
    }
    //移入暂停
    mySwiper.el.onmouseover = function () {
        mySwiper.autoplay.stop();
        mySwiper.navigation.$nextEl.css("display", "block");
        mySwiper.navigation.$prevEl.css("display", "block");
    }
}

//-------------------热门商品数据-----------------------

function getHotProduct() {
    $.get("../goodsAndShoppingCart/getGoodsList.php", { "typeId": "001" }, function (data) {
        // console.log(data);
        let oLi = '';
        for (let k in data) {
            // console.log(data[k]);
            oLi += `<li>
            <a href="javascript:;"></a>
            <div class="h_img"><img src="${data[k].goodsImg}" alt="" width="100%" height="100%"></div>
            <p class="h_p1">${data[k].goodsName}</p>
            <p class="h_p2">${data[k].goodsDesc}</p>
            <span>￥${data[k].goodsPrice}元</span>
            </li>`
        }
        $(".h_rmsp").html(oLi);

    }, "json")
}

//-------------------坚果配件数据-----------------------
function getParts() {
    $.get("../goodsAndShoppingCart/getGoodsList.php", { "typeId": "002" }, function (data) {
        // console.log(data);
        let oLi = '';
        oLi += `<li class="p_big p_bbod">
        <a href="javascript:;"></a>
        <img src="../img/10023.webp" alt="" width="100%" height="100%">
        </li>`;
        for (let k in data) {
            // console.log(data[k]);
            oLi += `
            <li class="p_bbod">
            <a href="javascript:;"></a>
            <div class="h_img"><img src="${data[k].goodsImg}" alt="" width="100%" height="100%"></div>
            <p class="h_p1">${data[k].goodsName}</p>
            <p class="h_p2">${data[k].goodsDesc}</p>
            <span>￥${data[k].goodsPrice}元</span>
            </li>`
        }
        $(".h_Jgzq").html(oLi);

    }, "json")
}

//-------------------TNT数据-----------------------
function getTnt() {
    $.get("../goodsAndShoppingCart/getGoodsList.php", { "typeId": "003" }, function (data) {
        // console.log(data);
        let oLi = '';
        oLi += `<li class="p_big p_bbod">
        <a href="javascript:;"></a>
        <img src="../img/10024.webp" alt="" width="100%" height="100%">
        </li>`;
        for (let k in data) {
            // console.log(data[k]);
            oLi += `
            <li class="p_bbod">
            <a href="javascript:;"></a>
            <div class="h_img"><img src="${data[k].goodsImg}" alt="" width="100%" height="100%"></div>
            <p class="h_p1">${data[k].goodsName}</p>
            <p class="h_p2">${data[k].goodsDesc}</p>
            <span>￥${data[k].goodsPrice}元</span>
            </li>`
        }
        $(".h_Tnt").html(oLi);

    }, "json")
}

//-------------------官方精选数据-----------------------

function getChoiceness() {
    $.get("../goodsAndShoppingCart/getGoodsList.php", { "typeId": "004" }, function (data) {
        // console.log(data);
        let oLi = '';
        oLi += `<li class="p_big p_bbod">
        <a href="javascript:;"></a>
        <img src="../img/10025.webp" alt="" width="100%" height="100%">
        </li>`;
        for (let k in data) {
            // console.log(data[k]);
            oLi += `
            <li class="p_bbod">
            <a href="javascript:;"></a>
            <div class="h_img"><img src="${data[k].goodsImg}" alt="" width="100%" height="100%"></div>
            <p class="h_p1">${data[k].goodsName}</p>
            <p class="h_p2">${data[k].goodsDesc}</p>
            <span>￥${data[k].goodsPrice}元</span>
            </li>`
        }
        $(".h_Gfjx").html(oLi);

    }, "json")
}
//-------------------足迹专区数据-----------------------

function getFootprint() {
    $.get("../goodsAndShoppingCart/getGoodsList.php", { "typeId": "005" }, function (data) {
        // console.log(data);
        let oLi = '';
        oLi += `<li class="p_big p_bbod">
        <a href="javascript:;"></a>
        <img src="../img/10028.webp" alt="" width="100%" height="100%">
        </li>`;
        for (let k in data) {
            // console.log(data[k]);
            oLi += `
            <li class="p_bbod">
            <a href="javascript:;"></a>
            <div class="h_img"><img src="${data[k].goodsImg}" alt="" width="100%" height="100%"></div>
            <p class="h_p1">${data[k].goodsName}</p>
            <p class="h_p2">${data[k].goodsDesc}</p>
            <span>￥${data[k].goodsPrice}元</span>
            </li>`
        }
        $(".h_ZuJi").html(oLi);

    }, "json")
}

//-------------------论坛专区数据-----------------------
function getForum() {
    $.get("../goodsAndShoppingCart/getGoodsList.php", { "typeId": "006" }, function (data) {
        // console.log(data);
        let oLi = '';
        for (let k in data) {
            // console.log(data[k]);
            oLi += `
            <li>
            <a href="" class="p_bottom"></a>
            <div class="f_oli">
                <div class="h_img"><img src="${data[k].goodsImg}" alt="" width="100%" height="100%"></div>
                <p class="h_p1">${data[k].goodsName}</p>
                <p class="h_p2">${data[k].goodsDesc}</p>
                <span class="f_top">${data[k].goodsPrice}</span>
            </div>
        </li>`

        }
        $(".h_take").html(oLi);

    }, "json")
}
